package org.example.dao.impl;

import org.example.dao.AccountDao;
import org.example.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        // 用于配置类创建对象
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public Account findAccount(String name) {
        return jdbcTemplate.queryForObject("select * from account where name = ?",new BeanPropertyRowMapper<Account>(Account.class),name);
    }

    @Override
    public Integer updateAccount(Account account) {
        return jdbcTemplate.update("update account set money = ? where id = ?",account.getMoney(),account.getId());
    }
}
